(function($){  
    //备份jquery的ajax方法  
    var _ajax=$.ajax;  
      
    //重写jquery的ajax方法  
    $.ajax=function(opt){  
        //备份opt中error和success方法  
        var fn = {  
        	beforeSend:function(jqXHR, settings){},
            error:function(XMLHttpRequest, textStatus, errorThrown){},  
            success:function(data, textStatus){}  
        }  
        if(opt.error){  
            fn.error=opt.error;  
        }  
        if(opt.success){  
            fn.success=opt.success;  
        }  
          
        //扩展增强处理  
        var _opt = $.extend(opt,{  
            error:function(XMLHttpRequest, textStatus, errorThrown){
            	var resData = XMLHttpRequest.responseText;
            	if(resData==""){
            		$(this).alertmsg('warn', "请稍后再试，程序猿正在努力开发中。。。");
            	}else{
            		var data = eval('(' + resData + ')');
                	var msg = '系统繁忙，请联系管理员！';
                	if(data.errType==2){
                		msg = data.message;
                	}
                	$(this).alertmsg('error', msg);
                	
            	}
            	//fn.error(XMLHttpRequest, textStatus, errorThrown);  
            },  
            success:function(data, textStatus){  
                //成功回调方法增强处理  
//            	layer.closeAll('loading');
                fn.success(data, textStatus);  
            },
            beforeSend:function(jqXHR, settings){
            	var data = settings.data;
            	var page = 1;
            	var limit = 20;
            	//如果查询包含分页参数
            	if(data!=undefined&&(data.indexOf("pageCurrent")!=-1||data.indexOf("pageSize")!=-1)){
            		var paramArr = data.split("&");
            		var num = 0;
            		for(var i=0;i<paramArr.length;i++){
            			if(paramArr[i].indexOf("pageCurrent")!=-1){
            				var keyValue = paramArr[i].split("=");
            				settings.data+="&page="+keyValue[1];
            				page=keyValue[1];
            				num++;
            			}
            			
            			if(paramArr[i].indexOf("pageSize")!=-1){
            				var keyValue = paramArr[i].split("=");
            				settings.data+="&limit="+keyValue[1];
            				limit=keyValue[1];
            				num++;
            			}
            			
            			if(num==2){
            				settings.data+="&start="+((page-1)*limit);
            				break;
            			}
            		}
            	}
            	fn.beforeSend(jqXHR, settings);
            }
        });  
        _ajax(_opt);  
    };  
})(jQuery);